/* 
 * Copyright © 2009 Perseus Project - Tufts University <http://www.perseus.tufts.edu>
 *
 * This file is part of OcroPerseus.
 *
 * OcroPerseus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * OcroPerseus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * JNI interface to Aspell APIs.
 */
package jaspellbridge;

/**
 * JNI interface to <code>aspellbridge</code>.
 * <code>aspellbridge</code> is a library written in C++ that must be present in your LD_LIBRARY_PATH. It accesses
 * Aspell APIs (see <http://aspell.net> for documentation and download).
 * <code>aspellbridge</code> updated source code is available at <http://www.himeros.eu>.
 * <p>
 * Official dictionaries for Aspell are available at <ftp://ftp.gnu.org/gnu/aspell/dict/0index.html>.
 * Ancient Greek dictionary for Aspell is grc. Updates before official releases are available at <http://www.himeros.eu>.
 *<p>
 * Jaspeller can be either instantiated or used statically:
 * <p>
 * <code>Jaspeller.init();</code><br/>
 * <code>String res=Jaspeller.aspellQuery(myWord,myLang);</code><br/>
 * ...<br/>
 * <code>Jaspeller.aspellQuery("","~"); //invoke the destructor</code>
 *
 * @author Federico Boschetti <federico.boschetti.73@gmail.com>
 */
public class Jaspeller {
    private static boolean inited=false;

    /**
     * Invoke the <code>init</code> method.
     */
    public Jaspeller(){
        init();
    }
    
    /**
     * Load <code>aspellbridge</code> library.
     */
    public static void init(){
        if(!inited){
            System.loadLibrary("aspellbridge");
            inited=true;
        }
    }

    /**
     *
     * The Aspell Engine is static, so it keeps in memory information for a specific language,
     * until the jLang parameter is changed (for example, switching from Greek to English and vice versa).
     * When jLang is set to "~", the speller destructor is invoked and memory is released.
     *
     * @param word the word to spell-check
     * @param lang the aspell dictionary (for example, grc for Ancient Greek).
     * @return the first parameter if the word is correct or a string with a list of suggestions separated by space if it is mispelled.
     */
    public static native String aspellQuery(String word, String lang);

}
